<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
    <title>主页</title>
    <meta charset="UTF-8"/>
    <link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/default/easyui.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/icon.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/easyui/demo/demo.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/easyui/wu.css}"/>
    <script type="text/javascript" th:src="@{/easyui/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/easyui/jquery.easyui.min.js}"></script>
    <script type="text/javascript" th:src="@{/easyui/locale/easyui-lang-zh_CN.js}"></script>
</head>
<body class="easyui-layout">
    <div data-options="region:'north',border:false" style="height:60px;padding:0;" class="wu-header">
        <div class="wu-header-left">
            <h1>运营后台管理系统</h1>
        </div>
        <div class="wu-header-right">
            <p><strong class="easyui-tooltip" sec:authentication="name"></strong>，欢迎您！</p>
            <p><a href="javascript:$('#updatePassword').dialog('open')">修改密码</a>|<a href="/logout">安全退出</a></p>
        </div>
    </div>
    <div class="wu-sidebar" data-options="region:'west',split:true,title:'功能菜单'" style="width:150px;">
        <div class="easyui-accordion" data-options="fit:true,border:false">
            <div th:each="menu:${menuList}" th:title="${menu.name}" style="padding: 10px">
                <ul class="easyui-tree wu-side-tree">
                    <li th:each="child:${menu.getChildren()}" iconCls="icon-users">
                        <a th:href="'javascript:add(\''+${child.name}+'\',\''+${child.url}+'\')'" data-icon="icon-users" th:text="${child.name}"></a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <div data-options="region:'center',title:''">
        <div id="tt" class="easyui-tabs" data-options="expand:true,fit:true">
            <div title="主面板" style="padding:20px;display:none;" >
                欢迎[<span sec:authentication="name"></span>]登录系统，现在时间是：<span id="time"></span>
            </div>
        </div>
    </div>


    <div id="updatePassword" class="easyui-dialog" title="修改密码" maximizable="true" resizable="true"
         style="width:50%;height:450px;width:800px;padding:10px" data-options="title:'修改密码',modal:true,closed:true">
        <div style="margin-bottom:20px">
            <input id="oldPassword" class="easyui-passwordbox" style="width:100%" data-options="label:'旧密码:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input id="newPassword" class="easyui-passwordbox" style="width:100%" data-options="label:'新密码:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input id="newPasswordAgain" class="easyui-passwordbox" style="width:100%" data-options="label:'再次输入新密码:',required:true">
        </div>
        <div style="text-align:center;padding:5px 0">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitUpdatePassword()"
               style="width:80px">保存</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="cancelForm('updatePassword')"
               style="width:80px">取消</a>
        </div>
    </div>
</body>
<script>
    function cancelForm(id) {
        $('#' + id).dialog('close');
    }
    function submitUpdatePassword() {
        var oldPassword = $.trim($("#oldPassword").val());
        var newPassword = $.trim($("#newPassword").val());
        var newPasswordAgain = $.trim($("#newPasswordAgain").val());
        if (oldPassword===''){
            $.messager.alert("提示", "旧密码不能为空");
        }else if (newPassword===''||newPassword.length<6){
            $.messager.alert("提示", "新密码不能为空，且不能小于6位");
        }else if (newPasswordAgain===''||newPasswordAgain.length<6){
            $.messager.alert("提示", "再次输入新密码不能为空，且不能小于6位");
        }else if(newPassword!=newPasswordAgain){
            $.messager.alert("提示", "两次输入的新密码不一致！");
        }else{
            $.post("/sys/user/updatePassword", {oldPassword:oldPassword,newPassword:newPassword}, function (result) {
                if (result == '1') {
                    console.log("success");
                    cancelForm('updatePassword');
                    $.messager.alert("提示", "修改密码成功！");
                }else if(result == '-2'){
                    $.messager.alert("提示", "旧密码不正确");
                } else {
                    $.messager.alert("提示", "操作错误");
                }
            });
        }
    }

    function add(title,url) {
        if ($('#tt').tabs('exists', title)) {
            $('#tt').tabs('select', title);//选中并刷新
        } else {
            $('#tt').tabs('add',{
                title:title,
                content:"<iframe src='"+url+"' name='iframe' frameBorder=0 scrolling=no width='100%;' style='height:99%;'></iframe>",
                closable:true
            });
        }
    }



    function IsPC() {
        var userAgentInfo = navigator.userAgent;
        var Agents = ["Android", "iPhone",
            "SymbianOS", "Windows Phone",
            "iPad", "iPod"];
        var flag = true;
        for (var v = 0; v < Agents.length; v++) {
            if (userAgentInfo.indexOf(Agents[v]) > 0) {
                flag = false;
                break;
            }
        }
        return flag;
    }

    function time(){
        var vWeek,vWeek_s,vDay;
        vWeek = ["星期天","星期一","星期二","星期三","星期四","星期五","星期六"];
        var date =  new Date();
        year = date.getFullYear();
        month = date.getMonth() + 1;
        if (month < 10) {
            month = "0"+month;
        }
        day = date.getDate();
        if (day < 10) {
            day = "0"+day;
        }
        hours = date.getHours();
        if (hours < 10) {
            hours = "0"+hours;
        }
        minutes = date.getMinutes();
        if (minutes < 10) {
            minutes = "0"+minutes;
        }
        seconds = date.getSeconds();
        if (seconds < 10) {
            seconds = "0"+seconds;
        }
        vWeek_s = date.getDay();
        if(IsPC()){
            document.getElementById("time").innerHTML = year + "-" + month + "-" + day + "\t" + hours + ":" + minutes +":" + seconds + "\t" + vWeek[vWeek_s] ;
        }else{
            document.getElementById("time").innerHTML = hours + ":" + minutes +":" + seconds;
        }

    };
    setInterval("time()",1000);

</script>
</html>